package com.controller;

import com.entity.Phone;
import com.resp.BaseResponseEntity;
import com.service.IPhoneService;
import com.service.impl.PhoneServiceimpl;
import com.utlils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 根据用户名查询用户信息
 */
@WebServlet("/findByIdPhone")
public class FindByIDPhoneController extends HttpServlet {
    IPhoneService service=new PhoneServiceimpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");

        String id = req.getParameter("id");
        int i = Integer.parseInt(id);
        Phone iphone = service.findById(i);

        BaseResponseEntity entity=null;

        if(id!=null){
            entity=new BaseResponseEntity(200,"ok",iphone);
        }else {
            entity=BaseResponseEntity.error();
        }
        ResponseUtils.responseToJson(resp,entity);



    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

}
